package com.api.gbhg.lbj.api;

import cn.hutool.core.util.StrUtil;
import com.google.common.base.Joiner;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import weaver.conn.RecordSet;
import weaver.soa.workflow.request.Cell;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;
import weaver.soa.workflow.request.RequestService;
import weaver.soa.workflow.request.DetailTable;
import weaver.soa.workflow.request.DetailTableInfo;
import weaver.soa.workflow.request.MainTableInfo;
import weaver.soa.workflow.request.Row;

import static com.api.gbhg.lbj.dao.ReimbursementDao.zyJinfeiQuery;

/**
 * @author lbj
 * @version 1.0
 * @description: TODO
 * @date 2021/2/1 11:22
 */
@Path("/gbhg/test")
public class TestApi {
    private final Logger logger= LoggerFactory.getLogger("gbhg");
    @GET
    @Path("/import")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public String getExcelTest(@Context HttpServletRequest request, @Context HttpServletResponse response) {
//        RecordSet rts=new RecordSet();
//        rts.executeQuery("select sheet7_detail1_field13 from formtable_main_161_dt5 where id=61");
//        rts.next();
        String superiorId1 = request.getParameter("id");
        List<String> superiorId = getSuperiorId(Integer.valueOf(superiorId1));
        String joinId = Joiner.on(",").join((Iterable<?>) superiorId);
        logger.info("joinId:"+joinId);
        return joinId;
//        logger.info("测试进入api创建流程");
//        RequestInfo requestinfo = new RequestInfo();
//        requestinfo.setCreatorid("1");//创建者ID
//        requestinfo.setWorkflowid("4"); // 工作流ID
//        requestinfo.setRequestlevel("0"); // 紧急程度:0正常，1重要，2紧急
//        requestinfo.setRemindtype("1"); // 提醒类型
//        requestinfo.setIsNextFlow("0");//不自动流转至下一节点
//        requestinfo.setDescription("描述");
//
//        MainTableInfo table = new MainTableInfo();
//        table.addProperty(getPro("gysbh", "666"));
//        requestinfo.setMainTableInfo(table);
//        DetailTableInfo tables = new DetailTableInfo();
//        DetailTable OneTable = new DetailTable();
//        OneTable.setId("1");//表示明细表1
//        for (int i = 0; i < 2; i++) {//明细表行数
//            Row row = new Row();
//            row.addCell(getCell("gys", "lbj"));
//            row.addCell(getCell("yhzh", "192991920"));
//            row.addCell(getCell("khh", "测试"));
//            OneTable.addRow(row);
//        }
//        tables.addDetailTable(OneTable);
//        requestinfo.setDetailTableInfo(tables);
//        RequestService requestService = new RequestService();
//        String requestid = "";
//        try {
//            requestid = requestService.createRequest(requestinfo);
//        } catch (Exception e) {
//            e.printStackTrace();
//
//        }
//        logger.info("流程创建成功=" + requestid);
//        return requestid;
//
//    }
//    public Property getPro(String field,String value) {
//        Property property = new Property();
//        property.setName(field);
//        property.setValue(value);
//        return property;
//    }
//    public Cell getCell(String field,String value) {
//        Cell cel = new Cell();
//        cel.setName(field);
//        cel.setValue(value);
//        return cel;
//    }
    }
    public static List<String> getSuperiorId(Integer id){
        List<String> list = new ArrayList<>();
        RecordSet rs = new RecordSet();
        String sql = " select sjzxsr from  uf_zyczbksr_xj where id = "+id+" ";
        rs.executeQuery(sql);
        rs.next();
        if (StrUtil.isNotEmpty(rs.getString("sjzxsr"))){
            List<String> sjzxsr = getSuperiorId(rs.getInt("sjzxsr"));
            list.addAll(sjzxsr);
        }
        list.add(String.valueOf(id));
        return list;
    }
}
